package com.bxd.baodan.widget;


import android.app.Service;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bxd.baodan.R;
import com.bxd.baodan.util.SpUtil;


public class CustomLinearLayout extends LinearLayout {

        private Context context = null;
        private LayoutInflater layoutInflater = null;
        
        private TextView key = null;
        private TextView value = null;
        
        public CustomLinearLayout(Context context, AttributeSet attrs) {
                super(context, attrs);
                this.context = context;
                this.layoutInflater = (LayoutInflater) this.context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
                View v = this.layoutInflater.inflate(R.layout.insure_param_layout, null);
                key = (TextView) v.findViewById(R.id.key);
                value = (TextView) v.findViewById(R.id.value);
                LayoutParams relLayoutParams=new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
                relLayoutParams.gravity = Gravity.CENTER_VERTICAL;
                this.addView(v,relLayoutParams);
            	this.setVisibility(View.GONE);
            	
        }
        
        /** 
		* <p>Title: </p> 
		* <p>Description: </p> 
		* @param context
		* @param attrs
		* @param defStyle 
		*/
		public CustomLinearLayout(Context context, AttributeSet attrs,
				int defStyle) {
			super(context, attrs, defStyle);
			// TODO Auto-generated constructor stub
		}

		/** 
		* <p>Title: </p> 
		* <p>Description: </p> 
		* @param context 
		*/
		public CustomLinearLayout(Context context) {
			super(context);
		this.layoutInflater = (LayoutInflater) this.context
				.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
		View v = this.layoutInflater
				.inflate(R.layout.insure_param_layout, null);
		key = (TextView) v.findViewById(R.id.key);
		value = (TextView) v.findViewById(R.id.value);
		}

		public void setContent(String key,String value){
        	this.key.setText(key);
        	this.value.setText(value);
        	//判断是否隐藏
        	this.setVisibility(View.VISIBLE);
        	if("否".equals(value) || "不购买".equals(value) ||  "".equals(value)){
        		this.setVisibility(View.GONE);
        	}else{
        		boolean isBule = SpUtil.getInstance().getBoolean("isBule");
        		SpUtil.getInstance().savaBoolean("isBule", !isBule);
        		if(isBule){
        			this.setBackgroundColor(this.getContext().getResources().getColor(R.color.blue_bg01));
        		}else{
        			this.setBackgroundColor(this.getContext().getResources().getColor(R.color.white));
        		}
        	}
        }
}
